from typing import BinaryIO

from .base import EndPointKit


class Medias(EndPointKit):
    async def a_upload_all(
        self,
        *,
        file_name: str,
        parent_type: str,
        parent_node: str,
        size: int,
        file: BinaryIO,
        extra: str = "",
        checksum: str = "",
    ) -> str:
        """
        上传素材
        https://open.larkoffice.com/document/server-docs/docs/drive-v1/media/upload_all?appId=cli_9faa5e0071b6500c
        """
        path = "/drive/v1/medias/upload_all"
        data = {
            "file_name": file_name,
            "parent_type": parent_type,
            "parent_node": parent_node,
            "size": size,
        }
        if checksum:
            data["checksum"] = checksum
        if extra:
            data["extra"] = extra

        files = {"file": file}
        resp = await self.app.afire("POST", path, params=None, body=None, data=data, files=files)
        data = self.app.parse_server_response(resp)
        return data["file_token"]
